<!DOCTYPE html>
<html lang="en">
<head>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="apple-touch-icon" href="https://alexxit.github.io/go2rtc/icons/apple-touch-icon-180x180.png" sizes="180x180">
    <link rel="icon" href="https://alexxit.github.io/go2rtc/icons/favicon.ico">
    <link rel="manifest" href="https://alexxit.github.io/go2rtc/manifest.json">
    <title>go2rtc - Stream</title>
    <style>
        body {
            background: black;
            margin: 0;
            padding: 0;
            display: flex;
            font-family: Arial, Helvetica, sans-serif;
        }

        html, body {
            height: 100%;
            width: 100%;
        }

        .flex {
            flex-wrap: wrap;
            align-content: flex-start;
            align-items: flex-start;
        }
    </style>
</head>
<body>
<script type="module" src="./video-stream.js"></script>
<script type="module">
    const params = new URLSearchParams(location.search);

    // support multiple streams and multiple modes
    const streams = params.getAll('src');
    const modes = params.getAll('mode');
    if (modes.length === 0) modes.push('');

    while (modes.length > streams.length) {
        streams.push(streams[0]);
    }
    while (streams.length > modes.length) {
        modes.push(modes[0]);
    }

    if (streams.length > 1) {
        document.body.className = 'flex';
    }

    const background = params.get('background') !== 'false';
    const width = '1 0 ' + (params.get('width') || '320px');

    for (let i = 0; i < streams.length; i++) {
        /** @type {VideoStream} */
        const video = document.createElement('video-stream');
        video.background = background;
        video.mode = modes[i] || video.mode;
        video.style.flex = width;
        video.src = new URL('api/ws?src=' + encodeURIComponent(streams[i]), location.href);
        document.body.appendChild(video);
    }
</script>
</body>
</html>
